package site.cilicili.frontend.course.domain.dto;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Optional;

/**
 * PROJECT:cilicili
 * PACkAGE:site.cilicili.frontend.course.domain.dto
 * Date:2024/3/16 23:07
 * EMAIL: chenbaiyi.work@gmail.com
 *
 * @author BaiYiChen
 */
@Data
public class GetCourseListResponse implements Serializable {
    @Serial
    @JsonIgnore
    private static final long serialVersionUID = -4035754716493701436L;

    private String view;
    private Long dm;
    private Integer id;
    private String title;
    private String faver;
    private String author;
    private String time;

    @JsonProperty("total_time")
    private String totalTime;

    private Detail detail;

    @JsonGetter("total_time")
    public String getJsonTotalTime() {
        return Optional.ofNullable(totalTime)
                .filter(StrUtil::isNotBlank)
                .map(str -> Optional.of(str)
                        .filter(s -> s.contains("时") && s.contains("钟") && s.contains("秒"))
                        .map(s -> s.substring(0, s.indexOf("钟") + 1))
                        .orElse(str))
                .orElse(totalTime);
    }

    @Data
    public static class Detail {
        private Video video;
        private DanMaKu danmaku;
        private List<HighLight> highlight;
    }

    @Data
    public static class Video {
        private String pic;
        private String url;
        private String type = "auto";
    }

    @Data
    public static class DanMaKu {
        private String id;
        private String api;
        private String token;
        private String maximum;
        private List<String> addition;
        private String user;
        private String bottom;
        private Boolean unlimited;
        private Double speedRate;
    }

    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    public static class HighLight {
        private Long time;
        private String text;
    }
}
